<template>
    <div>

    </div>
</template>

<script>
import { IsPC } from '@/utils/IsPC';
export default {
    async mounted() {
        let token = await this.getUrlParam(window.location.href, 'token');
        let nickname = await this.getUrlParam(window.location.href, 'nickname');
        let avatar = await this.getUrlParam(window.location.href, 'avatar');
        if (!IsPC()) {
            location.href = `http://m.synbiochallenges.com?token=${token}&nickname=${nickname}&avatar=${avatar}`;
            return;
        }
        this.$store.commit('setToken', token);
        this.$store.commit('setNickname', nickname);
        this.$store.commit('setAvatar', avatar);
        localStorage.setItem("last", 'weixin');
        let route = this.$store.state.backRouter
        this.$router.replace(route);
    },

    methods: {
        getUrlParam(sUrl, sKey) {
            sUrl = sUrl.toString();
            let allUrl = sUrl.split("?")[1].split("#")[0];

            if (sKey) {
                //指定参数名
                var strs = allUrl.split("&");
                var paramsArr = new Array();

                for (var i = 0, len = strs.length; i < len; i++) {
                    var temp = strs[i].split("=");
                    if (temp[0] === sKey) {
                        paramsArr.push(temp[1]);
                    }
                }
                if (paramsArr.length === 0) {
                    //找不到指定参数
                    return "";
                } else if (paramsArr.length === 1) {
                    //只匹配到一个唯一key
                    return paramsArr[0];
                } else {
                    //多个同名参数key
                    return paramsArr;
                }
            }
        },
    }
}
</script>

<style lang="less" scoped></style>